/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: asus
 * Date: 2025-01-06
 * Time: 10:38
 */
public class LongestCommonPrefix {
    public String longestCommonPrefix(String[] strs) {
        int minLen = Integer.MAX_VALUE;
        for (String str : strs) {
            if (str.length() < minLen) {
                minLen = str.length();
            }
        }
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < minLen; i++) {
            char c = strs[0].charAt(i);
            boolean flag = true;
            for (int j = 1; j < strs.length; j++) {
                if (c != strs[j].charAt(i)) {
                    flag = false;
                    break;
                }
            }
            if (!flag) {
                break;
            }
            stringBuilder.append(c);
        }
        return stringBuilder.toString();
    }
}
